<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新增帖子内容')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-blogcontent-add">
        	<div class="row">
        		<div class="form-group col-sm-6">    
	                <label class="col-sm-2 control-label">标题：</label>
	                <div class="col-sm-8">
	                    <input name="title" class="form-control" type="text">
	                </div>
	            </div>
	            <div class="form-group col-sm-6">    
	                <label class="col-sm-3 control-label textdanlan" title="选择正确的标签有助于提升帖子的曝光率哦...">标签：</label>
	                <div class="col-sm-8">
	                    <select name="tags" class="form-control m-b" th:with="type=${@dict.getType('blog_tags')}">
	                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                    </select>
	                </div>
	            </div>
        	</div>
        	<div class="row">
        		<div class="form-group">    
	                <label class="col-sm-1 control-label">内容：</label>
	                <div class="col-sm-10">
	                    <input type="hidden" class="form-control" name="content">
	                    <div class="summernote" id="content"></div>
	                </div>
	            </div>
        	</div>
            <div class="row">
	            <div class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label">开启评论：</label>
	                <div class="switch onoffswitch col-sm-1">
						<div class="onoffswitch">
							<input id="allowComment" name="allowComment" type="checkbox" value="1" class="onoffswitch-checkbox"> 
							<label class="onoffswitch-label" for="allowComment"> 
								<span class="onoffswitch-inner"></span>
								<span class="onoffswitch-switch"></span>
							</label>
						</div>
					</div>
	            </div>
	            <div class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label">是否发布：</label>
	                <div class="switch onoffswitch col-sm-1">
						<div class="onoffswitch">
							<input id="status" name="status" type="checkbox" value="1" checked="" class="onoffswitch-checkbox"> 
							<label class="onoffswitch-label" for="status"> 
								<span class="onoffswitch-inner"></span>
								<span class="onoffswitch-switch"></span>
							</label>
						</div>
					</div>
	            </div>
	            <div shiro:hasPermission="admin:admin:blog" class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label">是否为工具：</label>
	                <div class="switch onoffswitch col-sm-1">
						<div class="onoffswitch">
							<input id="istool" name="istool" type="checkbox" value="1" class="onoffswitch-checkbox"> 
							<label class="onoffswitch-label" for="istool"> 
								<span class="onoffswitch-inner"></span>
								<span class="onoffswitch-switch"></span>
							</label>
						</div>
					</div>
	            </div>
	            <div shiro:hasPermission="admin:admin:blog" class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label">是否热门：</label>
	                <div class="switch onoffswitch col-sm-1">
						<div class="onoffswitch">
							<input id="ishot" name="ishot" type="checkbox" value="1" class="onoffswitch-checkbox"> 
							<label class="onoffswitch-label" for="ishot"> 
								<span class="onoffswitch-inner"></span>
								<span class="onoffswitch-switch"></span>
							</label>
						</div>
					</div>
	            </div>
	            <div shiro:hasPermission="admin:admin:blog" class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label">类型：</label>
	                <div class="col-sm-7">
	                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('blog_type')}">
	                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                    </select>
	                </div>
	            </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "blog/blogcontent"
        $("#form-blogcontent-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-blogcontent-add').serialize());
            }
        }

        $("input[name='createDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='editDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                    	var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                    		type: "post",
                    		url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    			if (result.code == web_status.SUCCESS) {
                    				$('#' + obj.id).summernote('insertImage', result.url);
                    			} else {
                    				$.modal.alertError(result.msg);
                    			}
                    		},
                    		error: function(error) {
                    			$.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });
    </script>
</body>
</html>